package shop.maytinh.view;

import java.util.List;

import shop.maytinh.controller.*;
import shop.maytinh.model.*;

import com.opensymphony.xwork2.ActionSupport;


import shop.maytinh.util.*;


public class Home extends AbstractClass{	
	List<Product> listproduct=null;
	private Integer sotrang;
	private String searchPice;
	private String messenger;
	public String execute() {
		try{			
		ProductManager productmanager = new ProductManager();
		
		listproduct = productmanager.getlistproduct();	
		
	        return "success";
		}
		catch(Exception e){
			return "error";
		}
	}
	static Boolean isIntegerParseInt(String str) {
	    try {
	    	Integer.parseInt(str);
	        return true;
	    } catch (Exception e){}
	    return false;
	}

	public String searchpicepr()
	{
		try{	
			
			ProductManager productmanager = new ProductManager();
			
			if(isIntegerParseInt(searchPice))
			{
			int temp = Integer.parseInt(searchPice);
			listproduct = productmanager.SearchProductByPice(temp);
			}
			else
			{
				messenger="Please enter the number";
				listproduct=null;
			}
			
		        return "success";
			}
			catch(Exception e){
				return "error";
			}
		
	}
	public List<Product> getListproduct() {
		return listproduct;
	}
	public void setListproduct(List<Product> listproduct) {
		this.listproduct = listproduct;
	}
	public Integer getSotrang() {
		return sotrang;
	}
	public void setSotrang(Integer sotrang) {
		this.sotrang = sotrang;
	}
	public String getSearchPice() {
		return searchPice;
	}
	public void setSearchPice(String searchPice) {
		this.searchPice = searchPice;
	}
	public String getMessenger() {
		return messenger;
	}
	public void setMessenger(String messenger) {
		this.messenger = messenger;
	}

	
	
	
}
